<template>
	<view>
		
	
			<qiun-title-bar title="博客类别比例" />
			<view class="charts-box">
				<qiun-data-charts type="pie" :chartData="pie" />
			</view>
	
			<qiun-title-bar title="最新博客分析" />
			<view class="charts-box">
				<qiun-data-charts type="column" 
				:ontouch="true" :chartData="column" canvasId="scrollcolumnid" 
				:opts="{enableScroll:true,xAxis:{scrollShow:true,itemCount:4,disableGrid:true}}"  :canvas2d="true"/>
			</view>
	
	
			<qiun-title-bar title="常用标签词云" />
			<view class="charts-box">
				<qiun-data-charts type="word" :chartData="word" />
			</view>
	
	
	
		</view>
</template>

<script>
	export default {
		data() {
			return {
				
								pie: {},
								opts: {
									legend: {
										fontSize: 12
									}
								},
								column: {},
								word: {}
							}
		},
		onLoad() {
			this.getMyCategories();
			console.log(this.chartsDataPie1.series);
		},
		methods: {
				onPullDownRefresh() {
						this.getCategories()
						this.getTopBlogs()
						this.getTags()
						
					},
					onLoad() {
						this.getCategories()
						this.getTopBlogs()
						this.getTags()
					},
					methods: {
						getTags() {
							this.word = {}
							let json = {
								"series": []
							}
							let word = JSON.parse(JSON.stringify(json))
							let url = this.$params.host + this.$params.action_tags
							this.$request.get(url,res=>{
								url = this.$params.host + this.$params.action_tags_count
								res.data.forEach(async (t)=>{
									let r =await this.$request.requestAsync(url + t.id)
									if(r.data.success && r.data.data>0){
										let tag={
											name:t.name,
											textSize:parseInt(r.data.data) * 10>25?25 : parseInt(r.data.data) *10
										}
										word.series.push(tag)
									}
								})
								this.word = word
							},()=>{
									uni.stopPullDownRefresh()
							})
						},
						getTopBlogs() {
							this.column = {}
							let json = {
								"categories": [],
								"series": [{
									"name": "阅读量",
									"data": []
								}, {
									"name": "评论数",
									"data": []
								}]
							}
							this.column = JSON.parse(JSON.stringify(json))
							let url = this.$params.host + this.$params.action_hot
							this.$request.get(url, res => {
								res.data.forEach(blog => {
									this.column.categories.push(this.$util.ellipsis(blog.title, 10))
									this.column.series[0].data.push(blog.readCount)
									this.column.series[1].data.push(blog.comments.length)
								})
							}, () => {})
						},
						getCategories() {
							this.pie = {}
							let json = {
								"series": [{
									"data": []
								}]
							}
							this.pie = JSON.parse(JSON.stringify(json))
							let url = this.$params.host + this.$params.action_categories
							this.$request.get(url, res => {
								url = this.$params.host + this.$params.action_category_count
								res.data.forEach(async (c) => {
									let r = await this.$request.requestAsync(url + c.id)
									if (r.data.success && r.data.data > 0) {
										let category = {
											name: c.name,
											value: r.data.data
										}
										this.pie.series[0].data.push(category)
									}
								})
							}, () => {})
						}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	.charts-box {
		width: 100%;
		height: 300px;
	}
</style>